fix: early exit when userLocation is undefined - #13859
Conversation
| * `city.coordinates` is nullable in the schema and location updates can arrive without coordinates, | ||
| * so make sure we actually have numbers before handing them over to the map. | ||
| */ | ||
| const isValidLatLng = (location: any): location is { lat: number; lng: number } => { |
There was a problem hiding this comment.
any here throws away the type info the caller already has. userLocation comes from viewer.city?.coordinates, whose schema type is { lat: Float, lng: Float } (both nullable — data/schema.graphql:22546). Naming that shape keeps the guard honest and still narrows correctly:
| const isValidLatLng = (location: any): location is { lat: number; lng: number } => { | |
| const isValidLatLng = ( | |
| location: { lat?: number | null; lng?: number | null } | null | undefined | |
| ): location is { lat: number; lng: number } => { |
Not blocking — @typescript-eslint/no-explicit-any is off in this repo — but this PR is deleting a STRICTNESS_MIGRATION escape hatch, so it'd be nice not to add an any in its place.
| onPress={onPressCitySwitcherButton} | ||
| /> | ||
| {!!userLocation && ( | ||
| {!!isValidLatLng(userLocation) && ( |
There was a problem hiding this comment.
isValidLatLng already returns a boolean, so the !! is a no-op here (the old !!userLocation needed it to coerce an object).
| {!!isValidLatLng(userLocation) && ( | |
| {isValidLatLng(userLocation) && ( |
|
Summary Guards the map user-location button against The fix targets the right spot: Issues Found No blocking issues.
Areas Reviewed Bugs and edge cases: the Performance and architecture: nothing notable, the helper is a module-level pure function. Questions for Author
|
This PR resolves PHIRE-3337
Description
No UI changes, this PR just protects the user location button on the maps from being called with undefined lon + lat.
Fixes this sentry issue https://artsynet.sentry.io/issues/7529680301/events/f15319ccfbf4490280c6ad21e606af80/
PR Checklist
To the reviewers 👀
Changelog updates
Changelog updates
Cross-platform user-facing changes
iOS user-facing changes
Android user-facing changes
Dev changes
Need help with something? Have a look at our docs, or get in touch with us.